package com.ctakit.sdk.app;

import com.ctakit.sdk.SdkApplication;
import com.ctakit.sdk.http.okhttp.OkHttpUtils;
import com.ctakit.sdk.http.okhttp.cookie.CookieJarImpl;
import com.ctakit.sdk.http.okhttp.cookie.store.MemoryCookieStore;
import com.ctakit.sdk.http.okhttp.https.HttpsUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by imuto on 16/5/17.
 */
public class BaseApplication extends SdkApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        initConfig();
        initHttpConfig();

    }

    protected void initConfig(){

    }

    public   Map<String, String>  getGlobalHeaders(boolean isWebView){
        Map<String, String> headers = new ConcurrentHashMap<>();
        return headers;
    }

    protected void initHttpConfig(){

        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);

        CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
//                .addInterceptor(new LoggerInterceptor("TAG"))
                .cookieJar(cookieJar1)
                .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                .build();
        OkHttpUtils.initClient(okHttpClient);
    }

}
